﻿using System.Data;
using ContractManagementSystem.DataAccess;
using ContractManagementSystem.Entity;

namespace ContractManagementSystem.BusinessLogic
{
    public static class ConsultantBusiness
    {
        public static string ErrorMessage { get; set; }
        private static ConsultantDataAccess _consultantDataAccess;


        /// <summary>
        /// Function Select All Consultant
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="activeType"></param>
        /// <returns></returns>
        public static DataTable FetchAll(int activeType)
        {
            _consultantDataAccess = new ConsultantDataAccess();
            if (_consultantDataAccess.FetchAll(activeType) == null)
            {
                ErrorMessage = _consultantDataAccess.ErrorMessage;
            }
            return _consultantDataAccess.FetchAll(activeType);
        }

        /// <summary>
        /// Function SearchFullName
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static DataTable SearchFullName(string name)
        {
            _consultantDataAccess = new ConsultantDataAccess();
            if (_consultantDataAccess.SearchFullName(name) == null)
            {
                ErrorMessage = _consultantDataAccess.ErrorMessage;
            }
            return _consultantDataAccess.SearchFullName(name);
        }

        /// <summary>
        /// Function Select By Id Consultant
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="consultantEntity"></param>
        /// <returns></returns>
        public static DataTable FetchById(ConsultantEntity consultantEntity)
        {
            _consultantDataAccess = new ConsultantDataAccess();
            if(_consultantDataAccess.FetchById(consultantEntity)==null)
            {
                ErrorMessage = _consultantDataAccess.ErrorMessage;
            }
            return _consultantDataAccess.FetchById(consultantEntity);
        }

        /// <summary>
        /// Function Insert Consultant
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="consultantEntity"></param>
        /// <returns></returns>
        public static bool Insert(ConsultantEntity consultantEntity)
        {
            _consultantDataAccess = new ConsultantDataAccess();
            if(_consultantDataAccess.Insert(consultantEntity))
            {
                return true;
            }
            ErrorMessage = _consultantDataAccess.ErrorMessage;
            return false;
        }

        /// <summary>
        /// Function Update Consultant
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="consultantEntity"></param>
        /// <returns></returns>
        public static bool Update(ConsultantEntity consultantEntity)
        {
            _consultantDataAccess = new ConsultantDataAccess();
            if(_consultantDataAccess.Update(consultantEntity))
            {
                return true;
            }
            ErrorMessage = _consultantDataAccess.ErrorMessage;
            return false;
        }

        /// <summary>
        /// Function Delete Consultant
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="consultantEntity"></param>
        /// <returns></returns>
        public static bool Delete(ConsultantEntity consultantEntity)
        {
            _consultantDataAccess = new ConsultantDataAccess();
            if(_consultantDataAccess.Delete(consultantEntity))
            {
                return true;
            }
            ErrorMessage = _consultantDataAccess.ErrorMessage;
            return false;
        }
    }
}
